<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>地图单击拾取经纬度</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <meta content="initial-scale=1.0, user-scalable=no" name="viewport">
    <meta content="IE=Edge" http-equiv="X-UA-Compatible">
    <style>
        body,
        html,
        #container {
            overflow: hidden;
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
    <script src="js/jquery-3.5.1.min.js"></script>
    <link href="layui-v2.6.4/layui/css/layui.css" rel="stylesheet" type="text/css"/>
    <link href="layui-v2.6.4/layui/css/modules/code.css" rel="stylesheet" type="text/css"/>
    <script charset="utf-8" src="layui-v2.6.4/layui/layui.js" type="text/javascript"></script>
    <script src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=hPuA9MGHxpzS3vE5MiZu0y9EAMB0Cg07"></script>
</head>
<body>
<div id="container"></div>
</body>
</html>
<script>
    var map = new BMapGL.Map('container');
    var geo = new BMapGL.Geocoder();
    var weizhi;
    map.centerAndZoom(new BMapGL.Point(107.0601849011229, 33.075758669497986), 16);
    map.enableScrollWheelZoom(true);
    map.addEventListener('click', function (e) {
        var j = e.latlng.lng;
        var w = e.latlng.lat;
        var city = e.latlng;
        var marker = new BMapGL.Marker(new BMapGL.Point(j, w));
        map.addOverlay(marker);
        geo.getLocation(city, function (res) {
            weizhi = res.addressComponents;
            if (weizhi.street == "") {
                weizhi.street = "未命名地点"
            }
            if (weizhi.streetNumber == "") {
                weizhi.streetNumber = "未定义门牌号"
            }
            var weizhiinfo = weizhi.city + "," + weizhi.district + ',' + weizhi.street + "," + weizhi.streetNumber;
            var tips = '你的位置是:' + weizhiinfo;
            layer.confirm(tips, function (res) {
                $.get("/setRedisUserJW", {"jing": j, "wei": w, "info": weizhiinfo}, function (res) {
                    layer.msg(res);
                    if (res === 1) {
                        layer.msg("保存成功");
                        layer.closeAll('loading');
                        location.assign("")
                    } else {
                        layer.msg("系统故障了哦!");
                        layer.closeAll('loading');
                    }
                })
                layer.load(2);
                window.close();
            })
        })
    });
</script>
